package com.ruoyi.price.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.price.domain.MarketPrice;
import com.ruoyi.price.service.IMarketPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 市场价格Controller
 * 
 * @author shenke
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/price/price")
public class MarketPriceController extends BaseController
{
    @Autowired
    private IMarketPriceService marketPriceService;

    /**
     * 查询市场价格列表
     */
    @PreAuthorize("@ss.hasPermi('price:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(MarketPrice marketPrice)
    {
        startPage();
        List<MarketPrice> list = marketPriceService.selectMarketPriceList(marketPrice);
        return getDataTable(list);
    }

    /**
     * 导出市场价格列表
     */
    @PreAuthorize("@ss.hasPermi('price:price:export')")
    @Log(title = "市场价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MarketPrice marketPrice)
    {
        List<MarketPrice> list = marketPriceService.selectMarketPriceList(marketPrice);
        ExcelUtil<MarketPrice> util = new ExcelUtil<MarketPrice>(MarketPrice.class);
        util.exportExcel(response, list, "市场价格数据");
    }

    /**
     * 获取市场价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('price:price:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(marketPriceService.selectMarketPriceById(id));
    }

    /**
     * 新增市场价格
     */
    @PreAuthorize("@ss.hasPermi('price:price:add')")
    @Log(title = "市场价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MarketPrice marketPrice)
    {
        return toAjax(marketPriceService.insertMarketPrice(marketPrice));
    }

    /**
     * 修改市场价格
     */
    @PreAuthorize("@ss.hasPermi('price:price:edit')")
    @Log(title = "市场价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MarketPrice marketPrice)
    {
        return toAjax(marketPriceService.updateMarketPrice(marketPrice));
    }

    /**
     * 删除市场价格
     */
    @PreAuthorize("@ss.hasPermi('price:price:remove')")
    @Log(title = "市场价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(marketPriceService.deleteMarketPriceByIds(ids));
    }
}
